package com.itheima.mall.dubbo.api.pms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.itheima.mall.dubbo.mapper.pms.PmsProductMapper;
import com.itheima.mall.entity.domain.pms.Product;
import com.itheima.mall.entity.page.MyPage;
import org.apache.dubbo.config.annotation.DubboService;
import org.aspectj.lang.annotation.Around;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductServiceImpl extends ServiceImpl<PmsProductMapper, Product> implements PmsProductService {
    @Autowired
    private PmsProductMapper productMapper;

    /*@Autowired
    private PmsProductService pmsProductService;*/


    @Override
    public MyPage<Product> getPage(Integer pageNum, Integer pageSize, String keyword, Integer brandId, Integer productCategoryId, String productSn, Integer publishStatus, Integer verifyStatus) {
        Page<Product> productPage = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Product> lqw = new LambdaQueryWrapper<>();
        lqw.like(keyword != null, Product::getKeywords, keyword);
        lqw.eq(brandId != null, Product::getBrandId, brandId);
        lqw.eq(productCategoryId != null, Product::getProductCategoryId, productCategoryId);
        lqw.eq(productSn != null, Product::getProductSn, productSn);
        lqw.eq(publishStatus != null, Product::getPublishStatus, publishStatus);
        lqw.eq(verifyStatus != null, Product::getVerifyStatus, verifyStatus);
         productMapper.selectPage(productPage, lqw);
        //Page<Product> page  = page(productPage, lqw);
        MyPage<Product> page = MyPage.init(productPage);
        return page;
    }

    @Override
    public List<Product> getKeyword(String keyword) {
        LambdaQueryWrapper<Product> lqw = new LambdaQueryWrapper<>();
        lqw.like(keyword != null,Product::getKeywords,keyword);
        List<Product> productList = productMapper.selectList(lqw);
        return productList;
    }
}
